package org.ttitfly.workflow.factory;

import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 * ejb生成对象
 * 
 * @author 潘海春
 * @version 2008-12-24
 */
public class EJBObjectCreator implements ObjectCreator {

	/**
	 * 初始环境
	 */
	private InitialContext ctx;

	/**
	 * 构造函数
	 * 
	 * @param props
	 */
	public EJBObjectCreator(Properties props) {
		try {
			ctx = new InitialContext();
		} catch (NamingException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public Object createObject(String name)
			throws ObjectNameUnavailableException {
		try {
			return ctx.lookup(name);
		} catch (NamingException e) {
			throw new ObjectNameUnavailableException("不能找到名称为[" + name + "]的EJB组件！", e);
		}
	}

}
